<!--  -->
<template>
  <div>
    <PageTitle name="所有资料"><el-button type="primary" @click="editFn()">发布资料</el-button></PageTitle>

    <Table
    :isSelection='true'
      :is-index="true"
      :loading="loading"
      :table-data="tableData"
      :table-cols="tableCols"
      :pagination="pagination"
      @pageChange="pageChange"
    ></Table>

  </div>
</template>

<script setup>
import {data} from "@/json/allMaterial.json";

import { ElMessage, ElMessageBox } from "element-plus";
import { ref, reactive, getCurrentInstance, onMounted } from "vue";
const { proxy } = getCurrentInstance();
const loading = ref(false);
// 表格格式
const tableCols = [
  { label: "资料编号", prop: "resource_id" },
  { label: "标题", prop: "resource_name" },
  { label: "内容描述", prop: "resource_desc" },
  { label: "下载地址", prop: "download_url" },
  { label: "发布者", prop: "owner" },
  { label: "发布时间", prop: "upload_date" },
];
const tableData = ref(data);
const pagination = reactive({
  pageIndex: 1,
  pageSize: 10,
});

const pageChange = (val) => {
  Object.assign(pagination,val)
  query();
};
const query = () => {
  loading.value = true;
  proxy.$api
    .get(`/staff/page/${pagination.pageIndex}/${pagination.pageSize}`)
    .then(res => {
     
      loading.value = false;
      tableData.value = res.records
      pagination.total = res.total;
    })
    .catch(() => {
      loading.value = false;
    });
};
const give = (id) => {
  proxy.$msgbox
    .confirm("是否确定赋予权限?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    }).then(() => {
      proxy.$api
        .post(`/staff/addPermission/${id}`)
        .then(res => {
          query();
          proxy.$message({
            type: "success",
            message: "赋予权限成功",
          });
        });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消操作！",
      });
    });
};
const del = (id) => {
  proxy.$msgbox
    .confirm("是否确定删除权限?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    }).then(() => {
      proxy.$api
        .get(`/staff/deletePermission/${id}`)
        .then(res => {
          query();
          proxy.$message({
            type: "success",
            message: "删除成功",
          });
        });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消操作！",
      });
    });
};

let selectList = []
const handleSelectionChange = (val) => {
  selectList = val
};
const editFn = (id) => {
  if(selectList&&selectList.length>0){

  
  proxy.$msgbox
    .confirm("是否确定发布所选资料?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    }).then(() => {
      proxy.$message({
            type: "success",
            message: "操作成功！",
          });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消操作！",
      });
    });
    }else{
      proxy.$message({
            type: "error",
            message: "请选择需要发布的资料",
          });
    }
};



</script>
<style lang='scss' scoped>
</style>
